<?php include('header.php'); ?>
<?php 
include_once('lib/User.php');
include_once('lib/Sqlexecutor.php');
$username = isset($_SESSION['username']) ? $_SESSION['username'] : false;
$oldpass = isset($_POST['oldpass']) ? $_POST['oldpass'] : false;
$newpass = isset($_POST['newpass']) ? $_POST['newpass'] : false;
$errno = false;
if($oldpass && $newpass && $username)
{
    $dbh = new Sqlexecutor('localhost', 'tile', 'tile', 'tile');
    $u = new User($dbh);
    $res = $u->updatePassByID($oldpass, $newpass, $username);
    $errno = $res;
}
?>




			<div>
				<ul class="breadcrumb">
					<li>
						<a href="#">系统管理</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="#">修改密码</a>
					</li>
				</ul>
			</div>
	
			<div class="row-fluid sortable">
				<div class="box span12">
					<div class="box-header well" data-original-title>
						<h2><i class="icon-edit"></i> 修改密码</h2>
<!--
						<div class="box-icon">
							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
						</div>
-->
					</div>
					<div class="box-content">
						<form id="changePass" class="form-horizontal" action="" method="post">
							<fieldset>
                              <?php if($errno == -3) {?>  
                              <div class="alert alert-error">
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                 您输入的当前密码有误，请你更正后重新提交.
                              </div>
                              <?php }?>
                              <?php if($errno == -100) {?>  
                              <div class="alert alert-error">
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                系统内部错误，请稍后重试，或者联系管理员. 
                              </div>
                              <?php }?>
                              <?php if($errno > 0 || $errno === 0) {?>  
                              <div class="alert alert-success">
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                您修改的新密码已经生效.
                              </div>
                              <?php }?>
							  <div class="control-group">
								<label class="control-label" for="ocusedInput">当前密码</label>
								<div class="controls">
								  <input class="input-large focused" name="oldpass" id="oldpass" type="password" value="">
								</div>
							  </div>
							  <div class="control-group">
								<label class="control-label">新密码</label>
								<div class="controls">
								  <input class="input-large" id="newpass" name="newpass" type="password" value="">
								</div>
							  </div>
                              <div class="control-group">
								<label class="control-label">确认密码</label>
								<div class="controls">
								  <input class="input-large" id="repeatpass" name="repeatpass" type="password" value="">
								</div>
							  </div>
							  <div class="form-actions">
								<button type="submit" class="btn btn-primary">保存密码</button>
								<button class="btn">取消修改</button>
							  </div>
							</fieldset>
						  </form>
					</div>
				</div><!--/span-->
			
			</div><!--/row-->
		   
<?php include('footer.php'); ?>

<script>
$().ready(function() {
	// validate signup form on keyup and submit
	$("#changePass").validate({
		rules: {
			oldpass: "required",
			newpass: {
				required: true,
				minlength: 6
			},
			repeatpass: {
				required: true,
				equalTo: "#newpass"
			},
		},
		messages: {
			oldpass: "请输入当前密码",
			newpass: {
				required: "请输入新密码",
				minlength: "请输入至少6位(由字母，数字，符号组成)"
			},
			repeatpass: {
				required: "请确认您输入的新密码",
				equalTo: "两次输入的密码不匹配"
			},
		}
	});
});
</script>
<style type="text/css">
form.form-horizontal label.error, label.error {
    /* remove the next line when you have trouble in IE6 with labels in list */
    color: #bd4247;
    font-style: italic
}
</style>
